import wpath
from scripts.deploy.accounts import *
import brownie


STRATEGIES = [
    StrategyCreamYFI,
    StrategyCurveBTCVoterProxy,
    StrategyCurveBUSDVoterProxy,
    StrategyCurveEURVoterProxy,
    StrategyCurveYVoterProxy,
    StrategyCurve3CrvVoterProxy,
    StrategyDAICurve,
    StrategyDForceUSDC,
    StrategyDForceUSDT,
    # StrategyMKRVaultDAIDelegate,  # 合约部署出错
    StrategyTUSDCurve,
    StrategyVaultUSDC,
]

N = len(STRATEGIES)


def deploy():
    nonce_list = range(20, 31)

    def strategy_deployment(gov, controller, index):
        # gov 管理员地址，部署合约
        # controller 控制器地址

        Strategy = STRATEGIES[index]
        nonce = nonce_list[index]

        print("gov address:", gov)
        print("controller address", controller)
        print("Strategy", Strategy._name)

        strategy = gov.deploy(Strategy, controller)

        assert strategy.governance() == gov
        assert strategy.controller() == controller
        assert strategy.getName() == Strategy._name

    for index in range(N):
        strategy_deployment(gov, controller, index)


def config():
    contract_address_list = [
        "0x79435EBAcDF1A16AE6dB45839521A29cE6647B03",
        "0x2284dF3d85C51C54Adf0607285409e004B3e7E14",
        "0x057f775DbcD3C1a7D5A22Eef56D8c70177Ba5bF4",
        "0x5c0a6BCbE32405589791e276f0AACfd15Ff57ae7",
        "0x68a94419E1C242620e3f326c87c85AB327dbe64D",
        "0x5E3412Fe388720912C7AcbF9f7e5Ad23124f5812",
        "0xBc234828E835c6fb60eD07A7e989BafB875d2b23",
        "0xB2dD2F273C0dd7ff3c5387941a85b8Fb14E7DfE8",
        "0x8212D03e141DA4cC264D7cc4C9FbdF38629828c4",
        "0x9088EdB119CDD8F92872182A90511a6A17aFCc0B",
        "0xA001FefeCBcC2A242D059A06114B01B401D0e548",
    ]

    def strategy_setParams(accounts, gov, controller, getter, setter, val, index):
        if not val:
            val = accounts[1]

        Strategy = STRATEGIES[index]
        strategy = Strategy.at(contract_address_list[index])

        if not hasattr(strategy, getter):
            return  # Some combinations aren't valid

        getattr(strategy, setter)(val, {"from": accounts[1]})
        getattr(strategy, setter)(val, {"from": gov})
        assert getattr(strategy, getter)() == val

        if getter == "governance":
            getattr(strategy, setter)(val, {"from": gov})

    params = [
        ("governance", "setGovernance", None),
        ("controller", "setController", None),
        ("strategist", "setStrategist", None),
        ("fee", "setFee", 100),
        ("withdrawalFee", "setWithdrawalFee", 100),
        ("performanceFee", "setPerformanceFee", 1000),
    ]

    for index in range(N):
        for getter, setter, val in params:
            strategy_setParams(accounts, gov, controller, getter, setter, val, index)
